package com.example.admin.service;


import com.example.admin.common.Result;
import com.example.admin.entity.CommunityActivity;
import com.example.admin.mapper.ActivityMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ActivityService {


    @Autowired
    private ActivityMapper activityMapper;

    public List<CommunityActivity> selectActivityPage() {

       List<CommunityActivity> communityActivityList= activityMapper.selectActivityPage();
       return communityActivityList;
    }

    public Result addActivity(CommunityActivity communityActivity) {

       int count= activityMapper.addActivity(communityActivity);
       if(count==0)
       {
           return Result.error("400","新增失败");
       }

       return Result.success("新增成功");
    }

    public Result editActivity(CommunityActivity communityActivity) {

      int count=  activityMapper.editActivity(communityActivity);
        if(count==0)
        {
            return Result.error("400","修改失败");
        }

        return Result.success("修改成功");
    }

    public Result deleteActivityById(Integer activityId) {

       int count= activityMapper.deleteActivityById(activityId);
        if(count==0)
        {
            return Result.error("400","删除失败");
        }

        return Result.success("删除成功");
    }

    public List<CommunityActivity> selectActivityByName(String activityName) {
       List<CommunityActivity> communityActivityList= activityMapper.selectActivityByName(activityName);
       return communityActivityList;
    }
}
